package com.cloud.easy.im.handler.strategy.websocket;

import com.cloud.easy.im.argeement.Agreement;
import com.cloud.easy.im.argeement.AgreementType;
import com.cloud.easy.im.event.ServerEventListener;
import com.cloud.easy.im.handler.AbstractServerHandler;
import com.cloud.easy.im.handler.strategy.AgreementStrategy;
import io.netty.channel.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 处理登出请求
 *
 * @author wangjian
 * @version 0.1.0
 * @create 2020年09月21日11:01 上午
 */
public class AgreementWebSocketCLogoutHandler extends AgreementStrategy {

    private static final Logger logger = LoggerFactory.getLogger(AgreementWebSocketCLoginHandler.class);

    private final AbstractServerHandler serverHandler;

    public AgreementWebSocketCLogoutHandler(AbstractServerHandler serverHandler) {
        super(AgreementType.C.FROM_CLIENT_TYPE_OF_LOGOUT);
        this.serverHandler = serverHandler;
    }

    @Override
    public void handler(Channel session, Agreement dataFromClient, ServerEventListener serverEventListener) throws Exception {
        logger.debug("[WEB_SOCKET_LOGOUT]客户端" + dataFromClient.getFrom() + "通过自定义协议退出登陆，移除在线列表");
        serverHandler.sessionClosed(session);
    }
}
